#include "stdafx.h"
#include "MyControls/SequenceCmdImpl.h"
#include "MyControls/Sequence.h"
#include "MyControls/Resource.h"

namespace My {

BEGIN_MESSAGE_MAP(SequenceCmdImpl, CCmdTarget)
	ON_COMMAND(ID_WORK_AREA_SET_BEGIN, OnWorkAreaSetBegin)
	ON_UPDATE_COMMAND_UI(ID_WORK_AREA_SET_BEGIN, OnUpdateWorkAreaSetBegin)
	ON_COMMAND(ID_WORK_AREA_SET_END, OnWorkAreaSetEnd)
	ON_UPDATE_COMMAND_UI(ID_WORK_AREA_SET_END, OnUpdateWorkAreaSetEnd)
END_MESSAGE_MAP()

void SequenceCmdImpl::OnWorkAreaSetBegin()
{
	Sequence & seq = *GetSequence();
	Span w = seq.GetWorkArea();
	w.first = seq.GetCurrentFrame();
	seq.SetWorkArea(w);
}

void SequenceCmdImpl::OnUpdateWorkAreaSetBegin(CCmdUI* pCmdUI)
{
	Sequence & seq = *GetSequence();
	pCmdUI->Enable(!seq.IsEmpty() 
		&& seq.GetWorkArea().first != seq.GetCurrentFrame()
		&& seq.GetWorkArea().last > seq.GetCurrentFrame());
}

void SequenceCmdImpl::OnWorkAreaSetEnd()
{
	Sequence & seq = *GetSequence();
	Span w = seq.GetWorkArea();
	w.last = seq.GetCurrentFrame() + 1;
	seq.SetWorkArea(w);
}

void SequenceCmdImpl::OnUpdateWorkAreaSetEnd(CCmdUI* pCmdUI)
{
	Sequence & seq = *GetSequence();
	pCmdUI->Enable(!seq.IsEmpty() 
		&& seq.GetWorkArea().last-1 != seq.GetCurrentFrame()
		&& seq.GetWorkArea().first <= seq.GetCurrentFrame());
}

} //namespace My
